package manage.student;

import manage.student.MainTableView.MainViewTable;
import manage.student.MainTableView.MainViewTableModel;
import manage.util.DimensionUtil;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class MainView extends JFrame {
    //北部
    JPanel northPanel=new JPanel();
    JButton addBtn=new JButton("添加");
    JButton updateBtn=new JButton("修改");
    JButton deleteBtn=new JButton("删除");
    JTextField searchText=new JTextField(15);
    JButton searchBtn=new JButton("搜索");
    //中部
    JPanel centerPanel=new JPanel();
    MainViewTable mainViewTable=new MainViewTable();
    //南部
    JPanel southPanel=new JPanel();
    JButton preBtn=new JButton("上一页");
    JButton nextBtn=new JButton("下一页");


    public MainView(){
        super("学生管理系统");
        Container container=getContentPane();
        //添加组件(北)
        layoutNorth(container);
        //设置中间table
        layoutCenter(container);

        //(南)
        layoutSouth(container);


        //JFrame设置
        //设置屏幕大小
        setBounds(DimensionUtil.getBounds());
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setLocationRelativeTo(null);

        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(true);

        }

    private void layoutCenter(Container container) {
        //数据
        Vector<Vector<Object>>data=new Vector<>();
        Vector<Object> row1=new Vector<>();
        row1.addElement("1");
        row1.addElement("李星云");
        row1.addElement("男");
        row1.addElement("高三");
        row1.addElement("95");
        row1.addElement("99");
        row1.addElement("93");

        Vector<Object> row2=new Vector<>();
        row2.addElement("2");
        row2.addElement("姬如雪");
        row2.addElement("女");
        row2.addElement("高三");
        row2.addElement("99");
        row2.addElement("93");
        row2.addElement("95");

        Vector<Object> row3=new Vector<>();
        row3.addElement("3");
        row3.addElement("张子凡");
        row3.addElement("男");
        row3.addElement("高三");
        row3.addElement("95");
        row3.addElement("99");
        row3.addElement("93");

        Vector<Object> row4=new Vector<>();
        row4.addElement("4");
        row4.addElement("李茂贞");
        row4.addElement("男");
        row4.addElement("高三");
        row4.addElement("95");
        row4.addElement("99");
        row4.addElement("93");

        data.addElement(row1);
        data.addElement(row2);
        data.addElement(row3);
        data.addElement(row4);


        //
        MainViewTableModel mainViewTableModel=MainViewTableModel.assembleModel(data);
       mainViewTable.setModel(mainViewTableModel);
        mainViewTable.RenderRule();
        JScrollPane jScrollPane = new JScrollPane(mainViewTable);
       container.add(jScrollPane,BorderLayout.CENTER);

    }

    private void layoutSouth(Container container) {
        southPanel.add(preBtn);
        southPanel.add(nextBtn);
        container.add(southPanel,BorderLayout.SOUTH);
    }

    private void layoutNorth(Container container) {
        northPanel.add(addBtn);
        northPanel.add(deleteBtn);
        northPanel.add(searchBtn);
        northPanel.add(updateBtn);
        northPanel.add(searchText);
        container.add(northPanel,BorderLayout.NORTH);
    }

    public static void main(String[] args) {
        new MainView();
    }
}
